const express = require('express');
const app = express();
const adminModel = require('./db/model/adminModel');
require('./db');
app.use(express.json());
app.use(express.urlencoded())
app.post('/addAdmin', async (req, res) => {
    const {
        adminName,
        password,
        regTime
    } = req.body
    try {
        const findResult = await adminModel.findOne({
            adminName,
        })
        if (findResult) {
            return res.send({
                code: 10001,
                msg: "该用户名已经被注册",
                data: null
            })
        }
        await adminModel.create({
            adminName,
            password,
            regTime
        })
        res.send({
            code: 10000,
            msg: "用户名注册成功",
            data: null
        })
    } catch (error) {
        res.send({
            code: 10002,
            msg: "服务器异常",
            data: null
        })
        console.log(error);
    }

})
app.listen(8000, () => {
    console.log("服务器部署抽横岗，http://127.0.0.1:8000");
})